/*
 * EnigmaGM - A feature rich guild management system.
 * Copyright (C) 2007 ajiaojr.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */
package org.ajiaojr.enigmagm.client.widget;

import org.ajiaojr.enigmagm.client.data.PointSystem;
import org.ajiaojr.enigmagm.client.service.PointSystemService;
import org.ajiaojr.enigmagm.client.service.PointSystemServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ListBox;

import java.util.List;

/**
 * @author ajiaojr
 */
public class PointSystemsListBox extends ListBox {
  private static final PointSystemListBoxMessages MESSAGES =
      (PointSystemListBoxMessages) GWT.create(PointSystemListBoxMessages.class);

  public PointSystemsListBox() {
    super();
    addItem(MESSAGES.pleaseChoose(), "0");
    PointSystemServiceAsync pointSystemService =
        PointSystemService.Util.getInstance();
    pointSystemService.list(new AsyncCallback() {

      public void onFailure(Throwable caught) {
        Window.alert(caught.getMessage());
      }

      public void onSuccess(Object result) {
        List pointSystems = (List) result;
        for (int i = 0; i < pointSystems.size(); i++) {
          PointSystem ps = (PointSystem) pointSystems.get(i);
          addItem(ps.getPointSystemName(), Integer.toString(ps
              .getPointSystemID()));
        }
      }
    });
  }
}
